package Year22_Month06.day17;

import java.util.ArrayList;
import java.util.List;

public class 二叉树的所有路径_递归写法 {
    public List<String> binaryTreePaths(TreeNode root) {
        List<String> list = new ArrayList<>();
        if(root == null) return list;
        solve(root,"",list);
        return list;
    }

    public void solve(TreeNode node,String s,List<String> list){
        if(node == null) return;
        s += node.val;
        //如果说当前结点为叶子结点，那么就把当前节点的String加入到字符顺序表中
        if(node.left == null && node.right == null) list.add(s);
        else{
            //不为叶子结点，就往下走就行
            solve(node.left,s+"->",list);
            solve(node.right,s+"->",list);
        }
    }
}
